package com.hs.pre.sys.user;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.hs.pre.model.UserBean;

public class CreateUserBean {

	private HttpServletRequest request=null;
	private UserBean userBean = new UserBean();
	public CreateUserBean(HttpServletRequest request){
		this.request = request;
		this.init();
	}
	/**
	 * 初始参数
	 */
	private void init()
	{
		String userId = request.getParameter("userId");
		String loginId = request.getParameter("loginId");
		String pwd = request.getParameter("pwd");
		String userName = request.getParameter("userName");
		String isAdmin = request.getParameter("isAdmin");
		String email = request.getParameter("email");
		String id = request.getParameter("id");
		String createDate = request.getParameter("createDate");
		String isDelete = request.getParameter("isDelete");
//		String createIp = request.getParameter("createIp");
		String createIp = request.getRemoteHost();
		String signInState = request.getParameter("signInState");	
		if(isEffective(userId))
			this.userBean.setUserId(Long.parseLong(userId.trim()));
		if(isEffective(loginId))
			this.userBean.setLoginId(loginId.trim());
		if(isEffective(pwd))
			this.userBean.setPwd(pwd.trim());
		if(isEffective(userName))
			this.userBean.setUserName(userName.trim());
		if(isEffective(isAdmin))
			this.userBean.setIsAdmin(Integer.parseInt(isAdmin.trim()));
		if(isEffective(email))
			this.userBean.setEmail(email.trim());
		if(isEffective(id))
			this.userBean.setId(Long.parseLong(id.trim()));
		if(isEffective(createDate))
			this.userBean.setCreateDate(new Date(createDate.trim()));
		if(isEffective(isDelete))
			this.userBean.setIsDelete(Integer.parseInt(isDelete.trim()));
		if(isEffective(createIp))
			this.userBean.setCreateIp(createIp.trim());
		if(isEffective(signInState))
			this.userBean.setSignInState(Integer.parseInt(signInState.trim()));
		
	}
	
	public UserBean getUserBean(){
		
		return userBean;
	}
	/**
	 * 是否有效
	 * @param obj
	 * @return
	 */
	private boolean isEffective(String obj){
		if(obj == null)
			return false;
		else return !((obj =obj.trim()).equals(""));
	}
}
